home *** CD-ROM | disk | FTP | other *** search
- Path: indirect.indirect.com!tmarks
- From: tmarks@indirect.com (Tom Marks)
- Newsgroups: comp.lang.c
- Subject: Re: Arrays of strings (linking)
- Date: Sat, 6 Apr 1996 02:51:31 UNDEFINED
- Organization: Internet Direct, Inc.
- Message-ID: <tmarks.4.008E8EAF@indirect.com>
- References: <4jbkpg$5m7@news.ariadne-t.gr> <315B6DBA.655413B1@alcyone.com>
- NNTP-Posting-Host: s81.phxslip4.indirect.com
- X-Newsreader: Trumpet for Windows [Version 1.0 Rev B final beta #1]
-
- In article <315B6DBA.655413B1@alcyone.com> Erik Max Francis <max@alcyone.com> writes:
- >From: Erik Max Francis <max@alcyone.com>
- >Subject: Re: Arrays of strings (linking)
- >Date: Thu, 28 Mar 1996 20:57:30 -0800
-
- >Arnellos Argiris-TEIA wrote:
- >>
- >> I have problem writing a function that accepts two strings and then linking
- >> them together in a new string. I must also return a pointer to this new
- >> string. For example: if I pass "Hello" to string1 and "World" to string2
- >> the function must return a pointer to "Hello World!".
- >> Could anyone help me by giving me an example or any ideas.
-
- >Your use of the word "linking" here is confusing, since it has a very specific
- >meaning in C, and is unrelated to the type of operation you're describing
- >(which is string concatenation).
-
- >Look into the stdlib functions strcpy and strcat.
-
- >--
- char *concat_strings(char *_s1, char *_s2
- char *_rs )
- {
-
- char *_trs = _rs;
-
-
- while(*_s1)
- *_rs++ = *_s1++;
-
- while(*_s2)
- *_rs++ = *_s2++;
-
- *_rs = '\0';
-
- return _trs;
- }
-
- This code should do what you want. You send it 3 pointers. Pointer to string 1
- pointer to string 2 and a pointer to the resultant string.
-